<?php
// +----------------------------------------------------------------------
// | ebSIG
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.ebsig.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: liudaojian <liudaojian@ebsig.com>
// +----------------------------------------------------------------------

/**
 * CRM接口类
 * @author   liudaojian <liudaojian@ebsig.com>
 * @version 1.0
 */

namespace App\Service\Rpc;

class Crm
{

    private $instance;

    public function __construct()
    {
        //项目标识
        $project_index = config('system.project_index');
        if ($project_index) {

            $project_index = ucfirst($project_index);

            //根据项目标识，实例相应类
            $class_name = __NAMESPACE__  . '\Crm\\' .$project_index . 'Crm';
            $this->instance = new $class_name;

        }

    }
    /**
     * 重载方法
     * @param $name
     * @param $args_array
     * @return array
     */
    public function __call( $name, $args_array ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        if(!method_exists( $this->instance, $name)) {
            return ['code' => 404, 'message' => '未定义' . $name  . '方法'];
        }

        return $this->instance->$name( $args_array[0] );

    }

    /**
     * 会员开卡接口
     * @return mixed
     */
    public function openCard( $args_data  )
    {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->openCard($args_data);
    }

    /**
     * 会员绑卡接口
     * @return mixed
     */
    public function bindCard( $args_data )
    {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->bindCard($args_data);
    }


    /**
     * 根据手机号查询会员资料
     * @return mixed
     */
    public function customerQuery( $args_data )
    {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->customerQuery($args_data);

    }

    /**
     * 会员资料编辑
     * @return mixed
     */
    public function customerEdit( $args_data )
    {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->customerEdit($args_data);

    }

    /**
     * 积分查询接口
     * @return mixed
     */
    public function pointsQuery( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->pointsQuery($args_data);
    }

    /**
     * 积分接口增加
     * @return mixed
     */
    public function pointsAdd( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->pointsAdd($args_data);
    }

    /**
     * 积分扣减接口
     * @return mixed
     */
    public function pointsReduction( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->pointsReduction($args_data);
    }


    /**
     * 积分日志接口
     * @return mixed
     */
    public function pointsLogs( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->pointsLogs($args_data);
    }


    /**
     * 余额查询接口
     * @return mixed
     */
    public function accountQuery( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->accountQuery($args_data);
    }

    /**
     * 余额充值接口
     * @return mixed
     */
    public function recharge( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->recharge($args_data);
    }

    /**
     * 余额消费接口
     * @return mixed
     */
    public function consumption( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->consumption($args_data);
    }


    /**
     * 余额记录接口
     * @return mixed
     */
    public function accountLogs( $args_data ) {

        if (!is_object($this->instance)) {
            return ['code' => 404, 'message' => '实例对象没有找到'];
        }

        return $this->instance->accountLogs($args_data);
    }

}